<?php

namespace app\controller;

use app\model\Role as RoleModel;
use app\BaseController;
use app\Request;
use app\validate\Role as RoleValidate;

class Role extends BaseController
{
    //查询所有角色对应的用户
    public function index()
    {

        try {

            $model = new RoleModel();
            $data= $model->with('user')->select();
            return show(1,$data);
        } catch (\Exception $e) {
            return show(1, $e->getMessage());
        }
    }
    //查询指定角色对应的用户
    public function search(Request $request){
        try {
            $param = $request->param();
            validate(RoleValidate::class)->scene('search')->check($param);
            $model = new RoleModel();
            $user = $model->find($param['id']);
            $data = [];
            if($user){
                $data = $user->user;
            }
            return show(1,$data);
        }catch (\Exception $e){
            return show(0,$e->getMessage());
        }
    }
}